package com.example.projecttest;

import android.Manifest;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.util.Log;
import android.view.View;
import android.widget.Button;

import com.example.projecttest.base.BasePermissionActivity;
import com.example.projecttest.listener.OnRequestPermissionListener;

public class TestPermiss extends BasePermissionActivity implements View.OnClickListener {

    private Button mButton;
    private String[] permiss=new String[]{
            Manifest.permission.CALL_PHONE,
            Manifest.permission.CAMERA,
            Manifest.permission.READ_EXTERNAL_STORAGE
    };

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.test_permiss);

        initView();
    }

    private void initView() {
        mButton=$(R.id.mButton);
        mButton.setOnClickListener(this);
    }

    public <T> T $(int viewID){
        return (T) findViewById(viewID);
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()){
            case R.id.mButton:
                checkPermissions(permiss, 100, new OnRequestPermissionListener() {
                    @Override
                    public void onSuccessful(int[] grantResults) {
                        for (int i=0;i<grantResults.length;i++){
                            Log.d("rcl", "==onSuccessful: =="+grantResults[i]);
                        }
                    }

                    @Override
                    public void onFailure() {

                    }

                    @Override
                    public void onNullPermission() {

                    }
                });
                break;
        }
    }
}
